﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using SLS.DataBase;
using SLS.ExClassLib.Data;
using SLS.ExClassLib.MVVM;
namespace Cinch
{
    /// <summary>
    /// This is a WPF specific partial section of a ViewModelBase
    /// </summary>
    public abstract partial class ViewModelBase
    {
        #region Data
        public SLDBSET.GoodsMasterPropertyDataTable GoodsMasterProperty
        {
            get
            {
                return SetEnv.GoodsMasterProperty;
            }
        }
        private SLDBSET SetEnv
        {
            get
            {
                return ViewDataSet.SetEnv;
            }
        }
        public SLDBSET SetGlobal
        {
            get
            {
                return ViewDataSet.SetGlobal;
            }
        }
        private ExDataRow activeExDataRow = null;
        private ObservableCollection<WorkspaceData> viewsKey = new ObservableCollection<WorkspaceData>();
        private ObservableCollection<WorkspaceData> viewsData = new ObservableCollection<WorkspaceData>();
        private ObservableCollection<WorkspaceData> viewsCore = new ObservableCollection<WorkspaceData>();
        private IDataModel viewsDataModel;
        #endregion

        #region Public Properties
        public string BaseTable="";
        static PropertyChangedEventArgs viewsExRow = ObservableHelper.CreateArgs<ViewModelBase>(x => x.ActiveExDataRow);
        public ExDataRow ActiveExDataRow
        {
            get { return activeExDataRow; }
            set
            {
                activeExDataRow = value;
                NotifyPropertyChanged(viewsExRow);
                ActiveExDataRow_Changed(value);
            }
        }
        public virtual void ActiveExDataRow_Changed(ExDataRow row)
        {
        }
        public void BuildEnvDataSet(ExDataRow dwThis)
        {
            try
            {
                if (SetEnv == null)
                    return;
                //Here, will load the related table, but will not force to create any data. it willl leav to WorkFlow
                dwThis.LoadLifeData(5);
                foreach (DataTable tbTemp in dwThis.Set2Create.Tables)
                {
                    SetEnv.Tables[tbTemp.TableName].Clear();
                    SetEnv.Merge(tbTemp);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        static PropertyChangedEventArgs viewsKeyArgs = ObservableHelper.CreateArgs<ViewModelBase>(x => x.DocumentsKey);
        public ObservableCollection<WorkspaceData> DocumentsKey
        {
            get { return viewsKey; }
            set
            {
                viewsKey = value;
                NotifyPropertyChanged(viewsKeyArgs);
            }
        }
        static PropertyChangedEventArgs viewsArgsData = ObservableHelper.CreateArgs<ViewModelBase>(x => x.DocumentsData);
        public ObservableCollection<WorkspaceData> DocumentsData
        {
            get { return viewsData; }
            set
            {
                viewsData = value;
                NotifyPropertyChanged(viewsArgsData);
            }
        }
        static PropertyChangedEventArgs viewsArgsCore = ObservableHelper.CreateArgs<ViewModelBase>(x => x.DocumentsCore);
        public ObservableCollection<WorkspaceData> DocumentsCore
        {
            get { return viewsCore; }
            set
            {
                viewsCore = value;
                NotifyPropertyChanged(viewsArgsCore);
            }
        }

        static PropertyChangedEventArgs viewsDataModelArgs = ObservableHelper.CreateArgs<ViewModelBase>(x => x.ViewDataSet);
        public IDataModel ViewDataSet
        {
            get { return viewsDataModel; }
            set
            {
                viewsDataModel = value;
                NotifyPropertyChanged(viewsDataModelArgs);
            }
        }
           #endregion
    }
}
